/**
 * 
 */
package evance.server.spring.core.utils;

import java.lang.reflect.Method;

/**
 * @author BaoVuong
 *
 */
public class NameUtils {
	public static String getMethodName(Method method) {
		StringBuilder methodName = new StringBuilder();
		methodName.append(method.getReturnType().getName());
		methodName.append(" ");
		methodName.append(method.getDeclaringClass().getName());
		methodName.append(".");
		methodName.append(method.getName());
		methodName.append("(");
		if (method.getParameterTypes().length > 0) {
			methodName.append(method.getParameterTypes()[0].getName());
			for (int i = 1; i < method.getParameterTypes().length; i++) {
				methodName.append(",");
				methodName.append(method.getParameterTypes()[i].getName());
			}
		}
		methodName.append(")");
		return methodName.toString();
	}

	public static String getPropertyName(String methodName) {
		if (methodName.startsWith("get")) {
			if (methodName.length() > 3) {
				String propertyName = methodName.substring(3, 4).toLowerCase()
						+ methodName.substring(4, methodName.length());
				return propertyName;
			}
		} else if ((methodName.startsWith("is")) && (methodName.length() > 2)) {
			String propertyName = methodName.substring(2, 3).toLowerCase()
					+ methodName.substring(3, methodName.length());
			return propertyName;
		}

		return null;
	}
}
